From 5939baa55657d15c214695bbdad33f9827071c2d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 11 Jan 2012 02:43:16 +0100 Subject: [PATCH] styleproperty: Make query function take a vfunc This way we can use different methods to query properties and aren't bound to a GtkStyleProperties object. --- gtk/gtkcssshorthandproperty.c | 8 +-- gtk/gtkcssshorthandpropertyimpl.c | 96 ++++++++++++++-------------- gtk/gtkcssshorthandpropertyprivate.h | 4 +- gtk/gtkcssstyleproperty.c | 8 +-- gtk/gtkstyleproperties.c | 22 ++++++- gtk/gtkstyleproperty.c | 18 +++--- gtk/gtkstylepropertyprivate.h | 15 +++-- 7 files changed, 97 insertions(+), 74 deletions(-) diff --git a/gtk/gtkcssshorthandproperty.c b/gtk/gtkcssshorthandproperty.c index 2002cccb2f..c47b5305a1 100644 --- a/gtk/gtkcssshorthandproperty.c +++ b/gtk/gtkcssshorthandproperty.c @@ -75,13 +75,13 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty *property, static void _gtk_css_shorthand_property_query (GtkStyleProperty *property, - GtkStyleProperties *props, - GtkStateFlags state, - GValue *value) + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data) { GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property); - shorthand->query (shorthand, value, props, state); + shorthand->query (shorthand, value, query_func, query_data); } static gboolean diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c index 9c088ce84a..aff350a4a4 100644 --- a/gtk/gtkcssshorthandpropertyimpl.c +++ b/gtk/gtkcssshorthandpropertyimpl.c @@ -537,27 +537,27 @@ unpack_border (GtkCssShorthandProperty *shorthand, static void pack_border (GtkCssShorthandProperty *shorthand, GValue *value, - GtkStyleProperties *props, - GtkStateFlags state) + GtkStyleQueryFunc query_func, + gpointer query_data) { GtkCssStyleProperty *prop; GtkBorder border; const GValue *v; prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0); - v = _gtk_style_properties_peek_property (props, prop, state); + v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); if (v) border.top = g_value_get_int (v); prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 1); - v = _gtk_style_properties_peek_property (props, prop, state); + v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); if (v) border.right = g_value_get_int (v); prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 2); - v = _gtk_style_properties_peek_property (props, prop, state); + v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); if (v) border.bottom = g_value_get_int (v); prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 3); - v = _gtk_style_properties_peek_property (props, prop, state); + v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); if (v) border.left = g_value_get_int (v); @@ -587,24 +587,21 @@ unpack_border_radius (GtkCssShorthandProperty *shorthand, static void pack_border_radius (GtkCssShorthandProperty *shorthand, GValue *value, - GtkStyleProperties *props, - GtkStateFlags state) + GtkStyleQueryFunc query_func, + gpointer query_data) { GtkCssBorderCornerRadius *top_left; + GtkCssStyleProperty *prop; + const GValue *v; - /* NB: We are an int property, so we have to resolve to an int here. - * So we just resolve to an int. We pick one and stick to it. - * Lesson learned: Don't query border-radius shorthand, query the - * real properties instead. */ - gtk_style_properties_get (props, - state, - "border-top-left-radius", &top_left, - NULL); - - if (top_left) - g_value_set_int (value, top_left->horizontal); - - g_free (top_left); + prop = GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("border-top-left-radius")); + v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); + if (v) + { + top_left = g_value_get_boxed (v); + if (top_left) + g_value_set_int (value, top_left->horizontal); + } } static void @@ -690,35 +687,38 @@ unpack_font_description (GtkCssShorthandProperty *shorthand, static void pack_font_description (GtkCssShorthandProperty *shorthand, GValue *value, - GtkStyleProperties *props, - GtkStateFlags state) + GtkStyleQueryFunc query_func, + gpointer query_data) { PangoFontDescription *description; - char **families; - PangoStyle style; - PangoVariant variant; - PangoWeight weight; - double size; - - gtk_style_properties_get (props, - state, - "font-family", &families, - "font-style", &style, - "font-variant", &variant, - "font-weight", &weight, - "font-size", &size, - NULL); + const GValue *v; description = pango_font_description_new (); - /* xxx: Can we set all the families here somehow? */ - if (families) - pango_font_description_set_family (description, families[0]); - pango_font_description_set_size (description, round (size * PANGO_SCALE)); - pango_font_description_set_style (description, style); - pango_font_description_set_variant (description, variant); - pango_font_description_set_weight (description, weight); - g_strfreev (families); + v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-family"))), query_data); + if (v) + { + const char **families = g_value_get_boxed (v); + /* xxx: Can we set all the families here somehow? */ + if (families) + pango_font_description_set_family (description, families[0]); + } + + v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-size"))), query_data); + if (v) + pango_font_description_set_size (description, round (g_value_get_double (v) * PANGO_SCALE)); + + v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-style"))), query_data); + if (v) + pango_font_description_set_style (description, g_value_get_enum (v)); + + v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-variant"))), query_data); + if (v) + pango_font_description_set_variant (description, g_value_get_enum (v)); + + v = (* query_func) (_gtk_css_style_property_get_id (GTK_CSS_STYLE_PROPERTY (_gtk_style_property_lookup ("font-weight"))), query_data); + if (v) + pango_font_description_set_weight (description, g_value_get_enum (v)); g_value_take_boxed (value, description); } @@ -744,8 +744,8 @@ unpack_to_everything (GtkCssShorthandProperty *shorthand, static void pack_first_element (GtkCssShorthandProperty *shorthand, GValue *value, - GtkStyleProperties *props, - GtkStateFlags state) + GtkStyleQueryFunc query_func, + gpointer query_data) { GtkCssStyleProperty *prop; const GValue *v; @@ -759,7 +759,7 @@ pack_first_element (GtkCssShorthandProperty *shorthand, for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++) { prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0); - v = _gtk_style_properties_peek_property (props, prop, state); + v = (* query_func) (_gtk_css_style_property_get_id (prop), query_data); if (v) { g_value_copy (v, value); diff --git a/gtk/gtkcssshorthandpropertyprivate.h b/gtk/gtkcssshorthandpropertyprivate.h index 110fdc6ee9..a8bfaaeef0 100644 --- a/gtk/gtkcssshorthandpropertyprivate.h +++ b/gtk/gtkcssshorthandpropertyprivate.h @@ -49,8 +49,8 @@ typedef void (* GtkCssShorthandPropertyAssignFunc) (GtkCssS const GValue *value); typedef void (* GtkCssShorthandPropertyQueryFunc) (GtkCssShorthandProperty *shorthand, GValue *value, - GtkStyleProperties *props, - GtkStateFlags state); + GtkStyleQueryFunc query_func, + gpointer query_data); struct _GtkCssShorthandProperty { diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c index d547ce31f3..2fb28d9f83 100644 --- a/gtk/gtkcssstyleproperty.c +++ b/gtk/gtkcssstyleproperty.c @@ -117,13 +117,13 @@ _gtk_css_style_property_assign (GtkStyleProperty *property, static void _gtk_css_style_property_query (GtkStyleProperty *property, - GtkStyleProperties *props, - GtkStateFlags state, - GValue *value) + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data) { const GValue *val; - val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state); + val = (* query_func) (GTK_CSS_STYLE_PROPERTY (property)->id, query_data); if (val) { /* Somebody make this a vfunc */ diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c index 981c9cd30e..ecb79f52d4 100644 --- a/gtk/gtkstyleproperties.c +++ b/gtk/gtkstyleproperties.c @@ -605,6 +605,22 @@ _gtk_style_properties_peek_property (GtkStyleProperties *props, return property_data_match_state (prop, state); } +typedef struct { + GtkStyleProperties *props; + GtkStateFlags state; +} StyleQueryData; + +static const GValue * +style_query_func (guint id, + gpointer data) +{ + StyleQueryData *query = data; + + return _gtk_style_properties_peek_property (query->props, + _gtk_css_style_property_lookup_by_id (id), + query->state); +} + /** * gtk_style_properties_get_property: * @props: a #GtkStyleProperties @@ -625,6 +641,7 @@ gtk_style_properties_get_property (GtkStyleProperties *props, GtkStateFlags state, GValue *value) { + StyleQueryData query = { props, state }; GtkStyleProperty *node; g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE); @@ -643,7 +660,10 @@ gtk_style_properties_get_property (GtkStyleProperties *props, return FALSE; } - _gtk_style_property_query (node, props, state, value); + _gtk_style_property_query (node, + value, + style_query_func, + &query); return TRUE; } diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c index be86c97e5a..928bf58ed0 100644 --- a/gtk/gtkstyleproperty.c +++ b/gtk/gtkstyleproperty.c @@ -198,32 +198,32 @@ _gtk_style_property_assign (GtkStyleProperty *property, /** * _gtk_style_property_query: * @property: the property - * @props: The properties to query - * @state: The state to query * @value: (out): an uninitialized #GValue to be filled with the * contents of the lookup + * @query_func: The function to use to query properties + * @query_data: The data to pass to @query_func * * This function is called by gtk_style_properties_get() and in * turn gtk_style_context_get() and similar functions to get the * value to return to code using old APIs. **/ void -_gtk_style_property_query (GtkStyleProperty *property, - GtkStyleProperties *props, - GtkStateFlags state, - GValue *value) +_gtk_style_property_query (GtkStyleProperty *property, + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data) { GtkStylePropertyClass *klass; - g_return_if_fail (property != NULL); - g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props)); + g_return_if_fail (GTK_IS_STYLE_PROPERTY (property)); g_return_if_fail (value != NULL); + g_return_if_fail (query_func != NULL); klass = GTK_STYLE_PROPERTY_GET_CLASS (property); g_value_init (value, property->value_type); - klass->query (property, props, state, value); + klass->query (property, value, query_func, query_data); } void diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h index 58aaf2abc9..5ba4d85c20 100644 --- a/gtk/gtkstylepropertyprivate.h +++ b/gtk/gtkstylepropertyprivate.h @@ -39,6 +39,9 @@ typedef enum { GTK_STYLE_PROPERTY_INHERIT = (1 << 0) } GtkStylePropertyFlags; +typedef const GValue * (* GtkStyleQueryFunc) (guint id, + gpointer data); + struct _GtkStyleProperty { GObject parent; @@ -56,9 +59,9 @@ struct _GtkStylePropertyClass GtkStateFlags state, const GValue *value); void (* query) (GtkStyleProperty *property, - GtkStyleProperties *props, - GtkStateFlags state, - GValue *value); + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data); gboolean (* parse_value) (GtkStyleProperty * property, GValue *value, GtkCssParser *parser, @@ -82,9 +85,9 @@ gboolean _gtk_style_property_parse_value (GtkStyleProperty * GType _gtk_style_property_get_value_type(GtkStyleProperty * property); void _gtk_style_property_query (GtkStyleProperty * property, - GtkStyleProperties *props, - GtkStateFlags state, - GValue *value); + GValue *value, + GtkStyleQueryFunc query_func, + gpointer query_data); void _gtk_style_property_assign (GtkStyleProperty *property, GtkStyleProperties *props, GtkStateFlags state, -- 2.30.2